/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package trabalho.pkg3;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Victor
 */
//Lista de arquivos que estão em um nó
public class ListaArq {

    public static Vector list = null;
    public static File arquivo = null;
    public ListaArq() {
        list = new Vector();
        arquivo = new File("ListaFile.txt");
    }

    public void Salvar() throws IOException {
         
        if (arquivo.exists()) {
            arquivo.delete();
        }
        arquivo.createNewFile();//cria um arquivo
        FileWriter fw = new FileWriter(arquivo, true);
        PrintWriter out = new PrintWriter(fw);
        for (int i = 0; i < list.size(); i++) {
            out.println(list.elementAt(i));
            out.flush();
        }
    }
    
    public void LoadLista() {
        try {
            Scanner scanner = new Scanner(new FileInputStream(arquivo));
            while (scanner.hasNextLine()) {
                list.add(scanner.nextLine());

            }
        } catch (FileNotFoundException ex) {
            Logger.getLogger(ListaArq.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public void addElem(String nome) {
        list.add(nome);
    }
    
    public void remover(String nome) throws IOException {
        int i = 0;
        while (i < list.size()) {
            if (nome.equalsIgnoreCase((String) list.elementAt(i))) {
                list.remove(i);
            }
            i++;
        }
        Salvar();
    }
}
